﻿function DeleteCookie(name) 
{  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1); 
	var cval = GetCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()+"; path=/";
}
function GetCookie(name)
{ 
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen)
	{
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
		return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
function getCookieVal (offset)
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)endstr = document.cookie.length;  
	return decodeURIComponent(document.cookie.substring(offset, endstr));
}

function getCookieS(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)) return unescape(arr[2]);
	else return null;
}

function SetCookie(sName,sValue)
{
  //如果设置了过期时间 
  var date=new Date(); 
  var ms=300 * 60 * 1000; //每分钟有60秒，每秒1000毫秒 
  date.setTime(date.getTime()+ms);   
  //document.cookie="path=/"; 
  var sCookie = sName + "=" + encodeURIComponent(sValue)+";path=/;expires="+date.toGMTString();  
  document.cookie = sCookie;
   
}

/*--------------------------------------------------------------------------------------------------
*Author:
*CompletedDate:2008-07-01
*Editor:
*ModifiedDate:
*Version:V1.0
*Description:cookier操作类，静态方法get,set,erase(获取、添加、删除)
*Example:var x = new Cookie("name","value");Cookie.set(x);var y = Cookie.get("name");erase("name");
*--------------------------------------------------------------------------------------------------
*/
function Cookie(name,value,seconds)
{
	this.name = name;
	if(value==null) this.value="";
	else if((typeof value).toLowerCase()=="undefined") this.value = "";
	else this.value = value;
	var d = new Date();
	if((typeof seconds).toLowerCase()=="object") d = seconds;
	else if((typeof seconds).toLowerCase()=="number") d.setTime(d.getTime()+seconds);
	else d.setTime(d.getTime()+24*60*60*1000);
	this.expires = d;
}
//静态设置方法
Cookie.set = function(cookie)
{
	if(cookie instanceof Cookie)
	{
		document.cookie = escape(cookie.name)+"="+escape(cookie.value)+"; path=/;expires="+cookie.expires.toGMTString()+"/";
	}
}
//静态获取方法
Cookie.get = function(name)
{
	name = escape(name)+"=";
	var start,end;
	start = document.cookie.indexOf(name);
	if(start>=0)
	{
		start += name.length;
		end = document.cookie.indexOf(";",start);
		if(end==-1)
			end = document.cookie.length;
		result = unescape(document.cookie.substring(start,end));
	}
	else
		result = "";
	return result;
}
//静态删除方法
Cookie.erase =function(name)
{
	var d = new Date();
	d.setTime(d.getTime()-86400*1000);
	var c = new Cookie(name,"",d);
	Cookie.set(c);
}